<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
<style>
    [v-cloak] {
        display: none;
    }
</style>
<body>
    <div id="box">
        <!-- 加减乘除 -->
        <label for="num1_id">请输入第一个数:</label>
        <input id="num1_id" type="text" v-model="num1"><br>
        <label for="num2_id">请输入第二个数：</label>
        <input id="num2_id" type="text" v-model="num2"><br>
        <label for="result_id">计算结果：</label>
        <input type="text" id="result_id" v-model="result"><br>
        <button v-on:click="add">加</button><br>
        <button @click="subtrack">减</button><br>
        <button @click="cheng">乘</button><br>
        <button @click="chu">除</button>
    </div>
    <script>
        const vm = new Vue({
            el: '#box',
            data: {
                num1: 0,
                num2: 0,
                result: 0
            },
            methods: {
                add() {
                    //写逻辑时，一定要注意数据类型
                    this.result = this.num1 * 1 + this.num2 * 1;
                },
                subtrack() {
                    // 减法
                    this.result = this.num1 * 1 - this.num2 * 1;
                },
                cheng() {
                    this.result = this.num1 * 1 * this.num2 * 1;
                },
                chu() {
                    this.result = this.num1 * 1 / this.num2 * 1;
                }
            },
        })
    </script>
</body>
</html>